﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName ="Bag",menuName ="Items/Bag", order =1)]
public class bag : Item, IUsable
{
    [SerializeField]
    private int slots;
    [SerializeField]
    private GameObject bagPrefab;
    public bagScript MyBagScript { get; set; }
    public int Slots { get => slots;  }
    public bagButton MyBagButton { get; set; }

    public void initialize(int slots)
    {
        this.slots = slots;
    }
    
    public void use()
    {
        
        if (inventoryScript.MyInstance.CanAddbag)
        {
          
            ItemDelete();
            ConnectBagScript();
            if (MyBagButton == null)
            {
                inventoryScript.MyInstance.addBag(this);
            }
            else
            {
                inventoryScript.MyInstance.addBag(this,MyBagButton);
            }
            MyBagScript.MyBagIndex = MyBagButton.MyBagId;
            //Debug.Log("bag/use: MyBagIndex = " + MyBagScript.MyBagIndex);
            
        }
        
    }

    public void ConnectBagScript()
    {
        MyBagScript = Instantiate(bagPrefab, inventoryScript.MyInstance.transform).GetComponent<bagScript>();
        MyBagScript.SlotAdd(slots);
    }

    public override string Description()
    {
        return base.Description()+string.Format("\n{0} slots bag",Slots);
    }

}
